
import GameCtr from "../../Controller/GameCtr";
import { Game } from "./Game";

const { ccclass, property } = cc._decorator;

@ccclass
export default class nextJackCube extends cc.Component {

    @property([cc.Sprite])
    spr: cc.Sprite[] = [];

    @property([cc.SpriteFrame])
    arrSprJack: cc.SpriteFrame[] = [];

    gameRoom: Game = null;
    CubeSprid = [];
    CubeId = -1;
    isfly = false;
    isTouch = false;
    moveNd: cc.Node = null;
    originPos = null;
    onLoad() {
        this.originPos = new cc.Vec2(0, -700);
        for (let index = 0; index < this.node.childrenCount; index++) {
            let element = this.node.children[index];
            element.getComponent(cc.Sprite).spriteFrame = null;
        }
    }

    start() {

    }

    addCube(outCubeSprid) {
        for (let index = 0; index < outCubeSprid.length; index++) {
            let element = outCubeSprid[index];
            this.CubeSprid.push(element);
        }
        this.setCube();
    }

    isMax() {
        if (this.CubeSprid.length >= 6) {
            return true;
        }
        return false;
    }
    clear() {
        this.CubeSprid = [];
        this.setCube();
    }

    resetCube() {
        this.CubeSprid = [];
        this.setCube();
    }

    setCube() {
        for (let index = 0; index < this.node.childrenCount; index++) {
            let element = this.node.children[index];
            element.getComponent(cc.Sprite).spriteFrame = null;
        }
        for (let index = 0; index < this.CubeSprid.length; index++) {
            let id = this.CubeSprid[index];
            let element = this.node.children[id];
            element.getComponent(cc.Sprite).spriteFrame = this.arrSprJack[0];
        }
    }

    GotoOrginpos() {
        this.isfly = true;
        let canvas = cc.director.getScene().getChildByName("Canvas");
        if (this.originPos) {
            this.node.runAction(cc.sequence(
                cc.moveTo(0.2, this.originPos),
                cc.callFunc(function () {
                    this.moveNd.active = false;
                    delete this.moveNd;
                    this.isfly = false;
                    this.node.opacity = 255;
                }.bind(this))
            ));
        }
    }

}
